package com.laputa.service.method.impl;

import java.util.List;

import com.laputa.model.City;
import com.laputa.model.User;
import com.laputa.model.manager.CityManager;
import com.laputa.model.manager.FriendManager;
import com.laputa.model.manager.UserManager;
import com.laputa.service.method.FriendListService;
import com.laputa.service.model.FriendListData;
import com.laputa.service.model.MainFrameData;

public class FriendListServiceImpl implements FriendListService {
	
	private UserManager userManager;
	private FriendManager friendManager;
	private CityManager cityManager;
	private FriendListData friendListData;
	private MainFrameData friendFrame;
	
	public void setUserManager(UserManager userManager){
		this.userManager = userManager;
	}
	
	public void setFriendManager(FriendManager friendManager){
		this.friendManager = friendManager;
	}
	
	public void setCityManager(CityManager cityManager){
		this.cityManager = cityManager;
	}

	public void setFriendListData(FriendListData friendListData){
		this.friendListData = friendListData;
	}
	
	public void setFriendFrame(MainFrameData friendFrame){
		this.friendFrame = friendFrame;
	}
	
	public FriendListData getFriendList(String userID) {
		List<User> userList = friendManager.getFriendListObject(userID);
		this.friendListData.setUserList(userList);
		return this.friendListData;
	}

	public MainFrameData loadFriendFrame(String friendID) {
		Long id = Long.parseLong(friendID);
		City city = cityManager.getCityObject(userManager.getUser(id.toString()).getCity().toString(),id.toString());
		com.laputa.dao.model.User u = userManager.getUser(id.toString());
		String name = u.getName();
		this.friendFrame.setId(id);
		this.friendFrame.setName(name);
		this.friendFrame.setCity(city);
		this.friendFrame.setMoney(u.getMoney());
		return this.friendFrame;
	}

	public void addFriendByName(String userID, String friendName) {
		friendManager.addFriend(userID, friendName);
	}
}
